package com.example.myapplication;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

public class JetPackActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jetpack);
        //getLifecycle().addObserver(new MyObserver());
        getLifecycle().addObserver(new MyObserver2());
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        // 创建ViewModelStore
        ViewModelProvider provider = new ViewModelProvider(this);
        // 从viewModelStore获取，如果没有，从ViewModelProvider.Factory创建
        provider.get(MyViewModel.class);
    }
}
